<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>convert</title>
</head>
<body>
<script>
    const obj = {
        "a": {
            "b": {
                "c": {
                    "d": 1
                }
            }
        },
        "aa": 2,
        "c": [
            1,
            2
        ]
    }

    function convert(obj, str = '', res = {}) {
        const keys = Object.keys(obj);
        keys.forEach((item) => {
            const type = Object.prototype.toString.call(obj[item]).slice(8, -1);
            if (type === 'Object') {
                str += item + '.';
                convert(obj[item], str, res);
            } else if (type === 'Array') {
                obj[item].forEach((items, index) => {
                    const key = `${item}[${index}]`;
                    res[key] = items;
                });
            } else {
                str += item;
                res[str] = obj[item];
                str = '';
            }
        });
        return res;
    }

    console.log(convert(obj));
</script>
</body>
</html>